/**
 * Copyright (c) 2017-present PlatformIO <contact@platformio.org>
 * All rights reserved.
 *
 * This source code is licensed under the license found in the LICENSE file in
 * the root directory of this source tree.
 */

import * as vscode from 'vscode';
import { IS_WINDOWS } from "../constants";

class QuickItem extends vscode.TreeItem {
  constructor(label, command, args, collapsibleState, children) {
    super(label, collapsibleState);
    if (command) {
      this.command = {
        title: label,
        command,
        arguments: args,
      };
    }
    this.customChildren = children;
  }
}

export default class QuickAccessTreeProvider {
  getChildren(element) {
    if (element && element.customChildren) {
      return element.customChildren;
    }

    if (IS_WINDOWS) {
      // add a quick access item that can start SuperIDE
      return [
        new QuickItem(
          'Super IDE',
          undefined,
          undefined,
          vscode.TreeItemCollapsibleState.Expanded,
          [
            new QuickItem('Install WSL Ubuntu-22.04', 'si.installWSL2204'),
            new QuickItem('Install Dependencies for SuperIDE Core in WSL', 'si.installDependenciesforSuperIDECoreInWSL'),
            new QuickItem('Install SuperIDE Core in WSL', 'si.installSuperIDECoreInWSL'),
            new QuickItem('Start SuperIDE In WSL', 'si.startSuperIDEInWSL'),
          ]
        ),
      ];
    }

    return [
      new QuickItem(
        'SuperIDE Home',
        undefined,
        undefined,
        vscode.TreeItemCollapsibleState.Expanded,
        [
          new QuickItem('Open', 'si.showHome'),
        ]
      ),
      new QuickItem(
        'Debug',
        undefined,
        undefined,
        vscode.TreeItemCollapsibleState.Expanded,
        [
          new QuickItem('Start Debugging', 'si.startDebugging'),
          new QuickItem('Toggle Debug Console', 'workbench.debug.action.toggleRepl'),
        ]
      ),
      new QuickItem(
        'Miscellaneous',
        undefined,
        undefined,
        vscode.TreeItemCollapsibleState.Expanded,
        [
          new QuickItem('SuperIDE CLI', 'si.openSuperIDECLI'),
          new QuickItem('Clone Git Project', 'git.clone'),
          new QuickItem('New Terminal', 'si.newTerminal'),
          new QuickItem('Call SuperIDE', 'si.callSuperIDE'),
          new QuickItem('Upgrade SuperIDE', 'si.upgradeCore'),
          new QuickItem('New local terminal', 'si.newLocalTerminal'),
          new QuickItem('Show Release Notes', 'si.showReleaseNotes'),
        ]
      ),
    ];
  }

  getTreeItem(element) {
    return element;
  }
}
